limsTest.possibleresultChoosePage = {
    getGridParam: function () {
        var _this = this, columns = limsTest.getPossibleResultChooseListColumns(),
            requestData = this.param;
        _this.param.single ? columns.unshift({
            radio: true
        }) : columns.unshift({
            checkbox: true
        });
        return {
            type: 'grid',
            id: 'possibleresult-choose-list-grid',
            url: limsTest.possibleResultsUrl + '/queries',
            requestData: requestData,
            columns: columns,
            service: 'limsPossibleResultServiceImpl',
            toolbarAlign: 'left',
            filterOpen: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.INSERT',
                icon: 'add-row',
                onClick: function () {
                    var model = Gikam.create('modal', {
                        title: 'GIKAM.BUTTON.INSERT',
                        height: '250',
                        width: '400',
                    });
                    Gikam.create('layout', {
                        renderTo: model.window.$dom,
                        center: {
                            items: [{
                                type: 'form',
                                id: 'insert-form',
                                fields: limsTest.getPossibleResultFormFields(),
                                onLoadSuccess: function () {
                                },
                                columns: 1,
                                titleWidth: 120,
                                onRendered: function () {
                                    if (_this.param.analType && _this.param.analType === 'N') {
                                        Gikam.getComp('insert-form').addFieldValidator('originalResult', ['number'])
                                    }
                                }
                            }, {
                                type: 'btnToolbar',
                                items: [{
                                    type: 'button',
                                    text: 'GIKAM.BUTTON.CONFIRM',
                                    class: 'blue',
                                    icon: 'save',
                                    color: 'white',
                                    onClick: function () {
                                        var form = Gikam.getComp('insert-form');
                                        if (form.validate()) {
                                            var data = form.getData();
                                            data.testMethodId = _this.param.testMethodId_EQ
                                            data.analyteId = _this.param.analyteId_EQ
                                            Gikam.post(limsTest.possibleResultsUrl, Gikam.getJsonWrapper(null, [null, [data]])).done(function () {
                                                Gikam.getComp('possibleresult-choose-list-grid').refresh();
                                            })
                                            Gikam.getLastModal().close(data);
                                        }
                                    }
                                }, {
                                    type: 'button',
                                    text: 'GIKAM.BUTTON.CANCEL',
                                    icon: 'back',
                                    onClick: function () {
                                        Gikam.getLastModal().close();
                                    }
                                }]
                            }]
                        }
                    })
                }
            }, {
                type: 'button',
                text: 'GIKAM.BUTTON.DELETE',
                icon: 'remove-row',
                onClick: function () {
                    Gikam.getComp('possibleresult-choose-list-grid').deleteRows(limsTest.possibleResultsUrl);
                }
            },{
                type: 'button',
                text: 'GIKAM.BUTTON.BACK',
                icon: 'back',
                onClick: function () {
                    Gikam.getLastModal().close();
                }
            }],
            deleteFormatter: function (row) {
                return row.originalResult;
            },
        }
    },


    create: function () {
        var _this = this;
        Gikam.create('layout', {
            renderTo: Gikam.getLastModal().window.$dom,
            center: {
                items: [this.getGridParam()]
            }
        });
    },

    init: function (param) {
        this.param = param;
        this.create();
    }
};
